# calcualte phylogenetic community structure and do null model things.
# 
# Author: Guochun Shen
# Data:   2011-12-30
# Project:spatial statistic
# Email:  shenguochun@gmail.com
###############################################################################



quadrat_phylo=function(com,phyd,nxy,nsim,abadjust){
	xyrange=com$win$xrange
	xmax=ymax=xyrange[2]
	x=com$x
	y=com$y
	n=com$n
	tips=rownames(phyd)
	pd=as.numeric(phyd)
	nsp=length(tips)
	sp=com$marks$sp
	sp=match(sp,tips)-1
	tips=0:(nsp-1)
	#the total number of calculation is nsim+1
	nsim=nsim+1
	pvalues=rep(0,3)
	realmpd=rep(0,nxy^2)
	abadjust=as.numeric(abadjust)
	re=.C("quadratphylo",as.double(x), as.double(y), as.integer(n), as.integer(sp), 
			as.integer(tips),as.double(pd),as.integer(nxy),as.integer(nsim), 
			as.double(xmax),as.double(ymax),as.integer(nsp),
			as.double(pvalues),as.double(realmpd),as.integer(abadjust))[[12]]
	return(re)
}

